1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module pango.PgMiscellaneous;
26 
27 private import core.stdc.stdio;
28 private import glib.Str;
29 private import glib.StringG;
30 private import glib.c.functions;
31 private import pango.c.functions;
32 public  import pango.c.types;
33 
34 
35 /** */
36 public struct PgMiscellaneous
37 {
38 
39 	/**
40 	 * Checks if a character that should not be normally rendered.
41 	 *
42 	 * This includes all Unicode characters with "ZERO WIDTH" in their name,
43 	 * as well as *bidi* formatting characters, and a few other ones.
44 	 *
45 	 * This is totally different from [func@GLib.unichar_iszerowidth] and is at best misnamed.
46 	 *
47 	 * Params:
48 	 *     ch = a Unicode character
49 	 *
50 	 * Returns: %TRUE if @ch is a zero-width character, %FALSE otherwise
51 	 *
52 	 * Since: 1.10
53 	 */
54 	public static bool isZeroWidth(dchar ch)
55 	{
56 		return pango_is_zero_width(ch) != 0;
57 	}
58 
59 	/**
60 	 * Return the bidirectional embedding levels of the input paragraph.
61 	 *
62 	 * The bidirectional embedding levels are defined by the [Unicode Bidirectional
63 	 * Algorithm](http://www.unicode.org/reports/tr9/).
64 	 *
65 	 * If the input base direction is a weak direction, the direction of the
66 	 * characters in the text will determine the final resolved direction.
67 	 *
68 	 * Params:
69 	 *     text = the text to itemize.
70 	 *     length = the number of bytes (not characters) to process, or -1
71 	 *         if @text is nul-terminated and the length should be calculated.
72 	 *     pbaseDir = input base direction, and output resolved direction.
73 	 *
74 	 * Returns: a newly allocated array of embedding levels, one item per
75 	 *     character (not byte), that should be freed using [func@GLib.free].
76 	 *
77 	 * Since: 1.4
78 	 */
79 	public static ubyte* log2visGetEmbeddingLevels(string text, int length, PangoDirection* pbaseDir)
80 	{
81 		return pango_log2vis_get_embedding_levels(Str.toStringz(text), length, pbaseDir);
82 	}
83 
84 	/**
85 	 * Parses an enum type and stores the result in @value.
86 	 *
87 	 * If @str does not match the nick name of any of the possible values
88 	 * for the enum and is not an integer, %FALSE is returned, a warning
89 	 * is issued if @warn is %TRUE, and a string representing the list of
90 	 * possible values is stored in @possible_values. The list is
91 	 * slash-separated, eg. "none/start/middle/end".
92 	 *
93 	 * If failed and @possible_values is not %NULL, returned string should
94 	 * be freed using g_free().
95 	 *
96 	 * Params:
97 	 *     type = enum type to parse, eg. %PANGO_TYPE_ELLIPSIZE_MODE
98 	 *     str = string to parse
99 	 *     value = integer to store the result in
100 	 *     warn = if %TRUE, issue a g_warning() on bad input
101 	 *     possibleValues = place to store list of possible
102 	 *         values on failure
103 	 *
104 	 * Returns: %TRUE if @str was successfully parsed
105 	 *
106 	 * Since: 1.16
107 	 */
108 	public static bool parseEnum(GType type, string str, out int value, bool warn, out string possibleValues)
109 	{
110 		char* outpossibleValues = null;
111 
112 		auto __p = pango_parse_enum(type, Str.toStringz(str), &value, warn, &outpossibleValues) != 0;
113 
114 		possibleValues = Str.toString(outpossibleValues);
115 
116 		return __p;
117 	}
118 
119 	/**
120 	 * Parses a font stretch.
121 	 *
122 	 * The allowed values are
123 	 * "ultra_condensed", "extra_condensed", "condensed",
124 	 * "semi_condensed", "normal", "semi_expanded", "expanded",
125 	 * "extra_expanded" and "ultra_expanded". Case variations are
126 	 * ignored and the '_' characters may be omitted.
127 	 *
128 	 * Params:
129 	 *     str = a string to parse.
130 	 *     stretch = a `PangoStretch` to store the result in.
131 	 *     warn = if %TRUE, issue a g_warning() on bad input.
132 	 *
133 	 * Returns: %TRUE if @str was successfully parsed.
134 	 */
135 	public static bool parseStretch(string str, out PangoStretch stretch, bool warn)
136 	{
137 		return pango_parse_stretch(Str.toStringz(str), &stretch, warn) != 0;
138 	}
139 
140 	/**
141 	 * Parses a font style.
142 	 *
143 	 * The allowed values are "normal", "italic" and "oblique", case
144 	 * variations being
145 	 * ignored.
146 	 *
147 	 * Params:
148 	 *     str = a string to parse.
149 	 *     style = a `PangoStyle` to store the result in.
150 	 *     warn = if %TRUE, issue a g_warning() on bad input.
151 	 *
152 	 * Returns: %TRUE if @str was successfully parsed.
153 	 */
154 	public static bool parseStyle(string str, out PangoStyle style, bool warn)
155 	{
156 		return pango_parse_style(Str.toStringz(str), &style, warn) != 0;
157 	}
158 
159 	/**
160 	 * Parses a font variant.
161 	 *
162 	 * The allowed values are "normal", "small-caps", "all-small-caps",
163 	 * "petite-caps", "all-petite-caps", "unicase" and "title-caps",
164 	 * case variations being ignored.
165 	 *
166 	 * Params:
167 	 *     str = a string to parse.
168 	 *     variant = a `PangoVariant` to store the result in.
169 	 *     warn = if %TRUE, issue a g_warning() on bad input.
170 	 *
171 	 * Returns: %TRUE if @str was successfully parsed.
172 	 */
173 	public static bool parseVariant(string str, out PangoVariant variant, bool warn)
174 	{
175 		return pango_parse_variant(Str.toStringz(str), &variant, warn) != 0;
176 	}
177 
178 	/**
179 	 * Parses a font weight.
180 	 *
181 	 * The allowed values are "heavy",
182 	 * "ultrabold", "bold", "normal", "light", "ultraleight"
183 	 * and integers. Case variations are ignored.
184 	 *
185 	 * Params:
186 	 *     str = a string to parse.
187 	 *     weight = a `PangoWeight` to store the result in.
188 	 *     warn = if %TRUE, issue a g_warning() on bad input.
189 	 *
190 	 * Returns: %TRUE if @str was successfully parsed.
191 	 */
192 	public static bool parseWeight(string str, out PangoWeight weight, bool warn)
193 	{
194 		return pango_parse_weight(Str.toStringz(str), &weight, warn) != 0;
195 	}
196 
197 	/**
198 	 * Quantizes the thickness and position of a line to whole device pixels.
199 	 *
200 	 * This is typically used for underline or strikethrough. The purpose of
201 	 * this function is to avoid such lines looking blurry.
202 	 *
203 	 * Care is taken to make sure @thickness is at least one pixel when this
204 	 * function returns, but returned @position may become zero as a result
205 	 * of rounding.
206 	 *
207 	 * Params:
208 	 *     thickness = pointer to the thickness of a line, in Pango units
209 	 *     position = corresponding position
210 	 *
211 	 * Since: 1.12
212 	 */
213 	public static void quantizeLineGeometry(ref int thickness, ref int position)
214 	{
215 		pango_quantize_line_geometry(&thickness, &position);
216 	}
217 
218 	/**
219 	 * Scans an integer.
220 	 *
221 	 * Leading white space is skipped.
222 	 *
223 	 * Params:
224 	 *     pos = in/out string position
225 	 *     out_ = an int into which to write the result
226 	 *
227 	 * Returns: %FALSE if a parse error occurred
228 	 */
229 	public static bool scanInt(ref string pos, out int out_)
230 	{
231 		char* outpos = Str.toStringz(pos);
232 
233 		auto __p = pango_scan_int(&outpos, &out_) != 0;
234 
235 		pos = Str.toString(outpos);
236 
237 		return __p;
238 	}
239 
240 	/**
241 	 * Scans a string into a `GString` buffer.
242 	 *
243 	 * The string may either be a sequence of non-white-space characters,
244 	 * or a quoted string with '"'. Instead a quoted string, '\"' represents
245 	 * a literal quote. Leading white space outside of quotes is skipped.
246 	 *
247 	 * Params:
248 	 *     pos = in/out string position
249 	 *     out_ = a `GString` into which to write the result
250 	 *
251 	 * Returns: %FALSE if a parse error occurred
252 	 */
253 	public static bool scanString(ref string pos, StringG out_)
254 	{
255 		char* outpos = Str.toStringz(pos);
256 
257 		auto __p = pango_scan_string(&outpos, (out_ is null) ? null : out_.getStringGStruct()) != 0;
258 
259 		pos = Str.toString(outpos);
260 
261 		return __p;
262 	}
263 
264 	/**
265 	 * Scans a word into a `GString` buffer.
266 	 *
267 	 * A word consists of [A-Za-z_] followed by zero or more
268 	 * [A-Za-z_0-9]. Leading white space is skipped.
269 	 *
270 	 * Params:
271 	 *     pos = in/out string position
272 	 *     out_ = a `GString` into which to write the result
273 	 *
274 	 * Returns: %FALSE if a parse error occurred
275 	 */
276 	public static bool scanWord(ref string pos, StringG out_)
277 	{
278 		char* outpos = Str.toStringz(pos);
279 
280 		auto __p = pango_scan_word(&outpos, (out_ is null) ? null : out_.getStringGStruct()) != 0;
281 
282 		pos = Str.toString(outpos);
283 
284 		return __p;
285 	}
286 
287 	/**
288 	 * Skips 0 or more characters of white space.
289 	 *
290 	 * Params:
291 	 *     pos = in/out string position
292 	 *
293 	 * Returns: %FALSE if skipping the white space leaves
294 	 *     the position at a '\0' character.
295 	 */
296 	public static bool skipSpace(ref string pos)
297 	{
298 		char* outpos = Str.toStringz(pos);
299 
300 		auto __p = pango_skip_space(&outpos) != 0;
301 
302 		pos = Str.toString(outpos);
303 
304 		return __p;
305 	}
306 
307 	/**
308 	 * Splits a %G_SEARCHPATH_SEPARATOR-separated list of files, stripping
309 	 * white space and substituting ~/ with $HOME/.
310 	 *
311 	 * Params:
312 	 *     str = a %G_SEARCHPATH_SEPARATOR separated list of filenames
313 	 *
314 	 * Returns: a list of
315 	 *     strings to be freed with g_strfreev()
316 	 */
317 	public static string[] splitFileList(string str)
318 	{
319 		auto retStr = pango_split_file_list(Str.toStringz(str));
320 
321 		scope(exit) Str.freeStringArray(retStr);
322 		return Str.toStringArray(retStr);
323 	}
324 
325 	/**
326 	 * Trims leading and trailing whitespace from a string.
327 	 *
328 	 * Params:
329 	 *     str = a string
330 	 *
331 	 * Returns: A newly-allocated string that must be freed with g_free()
332 	 */
333 	public static string trimString(string str)
334 	{
335 		auto retStr = pango_trim_string(Str.toStringz(str));
336 
337 		scope(exit) Str.freeString(retStr);
338 		return Str.toString(retStr);
339 	}
340 
341 	/**
342 	 * Reads an entire line from a file into a buffer.
343 	 *
344 	 * Lines may be delimited with '\n', '\r', '\n\r', or '\r\n'. The delimiter
345 	 * is not written into the buffer. Text after a '#' character is treated as
346 	 * a comment and skipped. '\' can be used to escape a # character.
347 	 * '\' proceeding a line delimiter combines adjacent lines. A '\' proceeding
348 	 * any other character is ignored and written into the output buffer
349 	 * unmodified.
350 	 *
351 	 * Params:
352 	 *     stream = a stdio stream
353 	 *     str = `GString` buffer into which to write the result
354 	 *
355 	 * Returns: 0 if the stream was already at an %EOF character,
356 	 *     otherwise the number of lines read (this is useful for maintaining
357 	 *     a line number counter which doesn't combine lines with '\')
358 	 */
359 	public static int readLine(FILE* stream, StringG str)
360 	{
361 		return pango_read_line(stream, (str is null) ? null : str.getStringGStruct());
362 	}
363 }